package com.bsoft.AQS;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @program: demo
 * @description:
 * @author: hdh
 * @create: 2022:04:01 16:55
 */
   /*
   Condition接口中的awit后signal 方法实现线程的等待和唤醒
      1 松阳县人民医院cda模板的制作和sql的整理 与程序的测试
      2 浙大妇保掌上医护移动端对接钉钉，危机值推送 和危机值提醒
      3市三医院 预约挂号原来是二级目录改造为三级目录，原来开放7天现在为28天号源
       首诊病人由不支持在线建档，改造为支持在线建档

    实现等待通知两个约束
    先等待 后唤醒

    */

public class LockSupper1 {
    static Object objectLock = new Object();
    static Lock lock = new ReentrantLock();
    static Condition condition = lock.newCondition();

    public static void main(String[] args) {
        new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            lock.lock();

            try {
                System.out.println(Thread.currentThread().getName() + "\t" + "-------come in");
                try {
                    condition.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "\t" + "------  被唤醒");


            } finally {
                lock.unlock();
            }
        }, "A").start();

        new Thread(() -> {
            lock.lock();
            try {
                condition.signal();
                System.out.println(Thread.currentThread().getName() + "\t" + "----唤醒动作");

            } finally {
                lock.unlock();
            }
        }, "B").start();
    }
}
